﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.User;
using CE.Global;
using CE.Database;
using CE.UserAccess;

public partial class admin_new_crm_broker : System.Web.UI.Page
{
    string PageCode = "GGRPTRADBRMVBR";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/ManagementSecureLogin.aspx");
        }
        if (!IsPostBack)
        {
            ClearProcess();

            ddlUserRole.Enabled = true;
            if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
            {
                CheckPageAccess();
                ddlUserRole.Text = "100";
                ddlUserRole.Enabled = false;
            }
            txtActiveStatus.Text = "1";
            txtAgentId.Text = "0";
            if (Request.QueryString["BrokerId"] != null)
            {
                Int64 AgentId = 0;
                if (!Int64.TryParse(Request.QueryString["BrokerId"].ToString(), out AgentId))
                {
                    AgentId = 0;
                }
                txtAgentId.Text = AgentId.ToString();
            }
            if (txtAgentId.Text.Trim() == "0")
            {
                LoadBrokerList();
            }
            else
            {
                LoadBroker();
            }   
            if (txtActiveStatus.Text.Trim() == "0")
            {
                btnSubmit.Enabled = false;
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {        
        if (Page.IsValid)
        {
            if (CheckDOBValid())
            {
                if (CheckEffectiveDateValid())
                {
                    BrokerAccount _brokeraccount = new BrokerAccount();
                    BrokerAccountDB _brokeraccountdb = new BrokerAccountDB();

                    if (_brokeraccountdb.IsAlreadyExist(txtEmail.Text.Trim(), 200) && txtAgentId.Text == "0")
                    {
                        lblMessage.Text = "";
                        lblError.Text = "Email address is already Created!";
                        return;
                    }
                    else
                    {
                        lblMessage.Text = "";
                        lblError.Text = "";
                        Int64 _result = -1;

                        _brokeraccount.CEID = Convert.ToInt64(txtAgentId.Text.Trim());
                        _brokeraccount.UserId = "AUTOUSERID";
                        _brokeraccount.Email = txtEmail.Text.ToLower();
                        _brokeraccount.AuthCode = txtPassword.Text;
                        _brokeraccount.UserTypeId = 200;
                        _brokeraccount.Status = true;
                        _brokeraccount.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                        _brokeraccount.Info1 = ddlBrokerLevel.Text;
                        _brokeraccount.Info2 = Server.HtmlEncode(txtLicenseNumber.Text.Trim());
                        _brokeraccount.Info10 = ddlEffYear.Text + ddlEffMonth.Text + ddlEffDay.Text;
                        _brokeraccount.NInfo4 = Convert.ToInt32(ddlUserRole.Text);
                        _brokeraccount.NInfo5 = Convert.ToInt32(ddlCampaign.Text);
                        _brokeraccount.NInfo6 = Convert.ToInt32(ddlRenewal.Text);

                        _result = _brokeraccountdb.Insert(_brokeraccount);
                        _brokeraccount.CEID = _result;
                        if (_result > 0)
                        {
                            Int64 _profileresult = -1;
                            BrokerProfile _brokerprofile = new BrokerProfile();
                            BrokerProfileDB _brokerprofiledb = new BrokerProfileDB();

                            _brokerprofile.ProfileId = Convert.ToInt64(txtProfileId.Text.Trim());
                            _brokerprofile.RefCEUserId = _result;
                            _brokerprofile.Salutation = "Ms";
                            if (ddlGender.Text == "M")
                            {
                                _brokerprofile.Salutation = "Mr";
                            }
                            _brokerprofile.FirstName = CE.Global.General.ClearScriptTag(Server.HtmlEncode(txtTHFirstName.Text));
                            _brokerprofile.SurName = CE.Global.General.ClearScriptTag(Server.HtmlEncode(txtTHLastName.Text));
                            _brokerprofile.DOB = Convert.ToDateTime(Convert.ToInt32(ddlYear.Text) + "/" + Convert.ToInt32(ddlMonth.Text) + "/" + Convert.ToInt32(ddlDay.Text));
                            _brokerprofile.Gender = Convert.ToChar(ddlGender.Text);
                            _brokerprofile.Info1 = General.ClearScriptTag(Server.HtmlEncode(txtENFirstName.Text));
                            _brokerprofile.Info2 = General.ClearScriptTag(Server.HtmlEncode(txtENLastName.Text));
                            _brokerprofile.Info3 = General.ClearScriptTag(Server.HtmlEncode(txtNickName.Text));
                            _profileresult = _brokerprofiledb.Insert(_brokerprofile);
                            if (_profileresult > 0)
                            {
                                Int64 _contactresult = -1;
                                BrokerContact _brokercontact = new BrokerContact();
                                BrokerContactDB _brokercontactdb = new BrokerContactDB();

                                _brokercontact.ContactId = Convert.ToInt64(txtContactId.Text.Trim());
                                _brokercontact.Email = _brokeraccount.Email;
                                _brokercontact.OfficePhone = Server.HtmlEncode(txtDIDNumber.Text.Trim());
                                string _Broker = "Broker";
                                if (ddlUserRole.Text == "100")
                                {
                                    _Broker = "Broker" + ddlUser.Text;
                                }
                                else if (ddlUserRole.Text == "200")
                                {
                                    _Broker = "Admin";
                                }
                                else if (ddlUserRole.Text == "300")
                                {
                                    _Broker = "Cashier";
                                }
                                string THContact = "";
                                string ENContact = "";
                                if (txtTHContact.Text.Trim().Length > 5)
                                {
                                    THContact = txtTHContact.Text.Trim();
                                }
                                else
                                {
                                    THContact = lblTHContact.Text + txtTHContact.Text.Trim();
                                }
                                if (txtTHContact.Text.Trim().Length > 5)
                                {
                                    ENContact = txtENContact.Text.Trim();
                                }
                                else
                                {
                                    ENContact = lblENContact.Text + txtENContact.Text.Trim();
                                }
                                if (THContact.ToString().Trim().Length <= 0)
                                {
                                    THContact = "02-268-8222";
                                }
                                if (ENContact.ToString().Trim().Length <= 0)
                                {
                                    ENContact = "02-268-8222";
                                }
                                _brokercontact.Info1 = _Broker;
                                _brokercontact.Einfo2 = Server.HtmlEncode(txtDIDNumber.Text.Trim());
                                _brokercontact.Einfo4 = Server.HtmlEncode(ENContact.ToString());
                                _brokercontact.Einfo5 = Server.HtmlEncode(THContact.ToString());
                                _brokercontact.Status = true;
                                _brokercontact.RefCEUserId = _brokeraccount.CEID;
                                _contactresult = _brokercontactdb.Insert(_brokercontact);
                                if (_contactresult > 0)
                                {
                                    ClearProcess();
                                    LoadBrokerList();
                                    lblMessage.Text = "Successfully Created!";
                                    lblError.Text = "";
                                }
                                else
                                {
                                    lblMessage.Text = "";
                                    lblError.Text = "Contact Details Insert Error";
                                }
                            }
                            else
                            {
                                lblMessage.Text = "";
                                lblError.Text = "Profile Details Insert Error";
                            }
                        }
                        else
                        {
                            lblMessage.Text = "";
                            lblError.Text = "Account Details Insert Error";
                        }
                    }
                }
                else
                {
                    lblMessage.Text = "";
                    lblError.Text = "Invalid Effective Date";
                    return;
                }
            }
            else
            {
                lblMessage.Text = "";
                lblError.Text = "Invalid DOB";
                return;
            }
        }
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        ClearProcess();
    }

    protected void btnView_Click(object sender, EventArgs e)
    {
        Response.Redirect("view-crm-brokers.aspx");
    }

    protected void ddlUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (txtAction.Text == "1")
        {
            string BrokerCode = "";
            if (ddlUserRole.Text == "100")
            {
                BrokerCode = "Broker" + ddlUser.Text;
            }
            if (ddlUserRole.Text == "200" || ddlUserRole.Text == "201")
            {
                BrokerCode = "Admin";
            }
            if (ddlUserRole.Text == "300")
            {
                BrokerCode = "Cashier";
            }
            LoadBroker(Convert.ToInt16(ddlUser.Text), BrokerCode);
            txtPassword.Text = GetAutoPassword();
        }
    }

    protected void ddlUserRole_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearProcess();
        LoadBrokerList();
    }

    private void ClearProcess()
    {
        lblError.Text = "";
        lblMessage.Text = "";
        //ddlUser.SelectedIndex = 0;
        txtEmail.Text = "";
        txtPassword.Text = "";
        ddlRenewal.Text = "0";
        ddlBrokerLevel.SelectedIndex = 0;
        txtLicenseNumber.Text = "";
        txtENContact.Text = "";
        txtTHContact.Text = "";
        txtDIDNumber.Text = "";
        txtTHFirstName.Text = "";
        txtTHLastName.Text = "";
        txtENFirstName.Text = "";
        txtENLastName.Text = "";
        txtNickName.Text = "";

        ddlDay.Items.Clear();
        ddlMonth.Items.Clear();
        ddlYear.Items.Clear();

        int _cryr = CE.Global.General.GetUTCDateTime().Year;
        int _styr = _cryr - 70;
        int _edyr = _cryr - 18;
        ddlDay.Items.Add(new ListItem("dd", "00"));
        ddlMonth.Items.Add(new ListItem("mm", "00"));
        ddlYear.Items.Add(new ListItem("yyyy", "0000"));
        for (int _year = _edyr; _year >= _styr; _year--)
        {
            ddlYear.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
        }
        for (int _dd = 1; 31 >= _dd; _dd++)
        {
            string day = _dd.ToString();
            if (_dd.ToString().Length < 2)
            {
                day = "0" + _dd.ToString();
            }
            ddlDay.Items.Add(new ListItem(day, day));
        }
        for (int _mm = 1; 12 >= _mm; _mm++)
        {
            string month = _mm.ToString();
            if (_mm.ToString().Length < 2)
            {
                month = "0" + _mm.ToString();
            }
            ddlMonth.Items.Add(new ListItem(GetMonth(month), month));
        }

        ddlEffDay.Items.Clear();
        ddlEffMonth.Items.Clear();
        ddlEffYear.Items.Clear();

        int _efcryr = CE.Global.General.GetUTCDateTime().Year;
        int _efstyr = 2012;
        int _efedyr = _cryr + 1;
        ddlEffDay.Items.Add(new ListItem("dd", "00"));
        ddlEffMonth.Items.Add(new ListItem("mm", "00"));
        ddlEffYear.Items.Add(new ListItem("yyyy", "0000"));
        for (int _effyear = _efedyr; _effyear >= _efstyr; _effyear--)
        {
            ddlEffYear.Items.Add(new ListItem(_effyear.ToString(), _effyear.ToString()));
        }
        for (int _effdd = 1; 31 >= _effdd; _effdd++)
        {
            string effday = _effdd.ToString();
            if (_effdd.ToString().Length < 2)
            {
                effday = "0" + _effdd.ToString();
            }
            ddlEffDay.Items.Add(new ListItem(effday, effday));
        }
        for (int _effmm = 1; 12 >= _effmm; _effmm++)
        {
            string effmonth = _effmm.ToString();
            if (_effmm.ToString().Length < 2)
            {
                effmonth = "0" + _effmm.ToString();
            }
            ddlEffMonth.Items.Add(new ListItem(GetMonth(effmonth), effmonth));
        }
        string _d = CE.Global.General.GetUTCDateTime().ToString("dd");
        string _m = CE.Global.General.GetUTCDateTime().ToString("MM");
        string _y = CE.Global.General.GetUTCDateTime().ToString("yyyy");
        ddlEffDay.Text = _d.ToString();
        ddlEffMonth.Text = _m.ToString();
        ddlEffYear.Text = _y.ToString();
        //lblEffectiveUpTo.Text = "31/Dec/2025";
    }

    private void LoadBrokerList()
    {
        
            ddlUser.Items.Clear();
            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            DataSet _dsUserList = new DataSet();
            DataTable _dtUser = new DataTable();
            SortedList _sPara = new SortedList();
            _sPara.Add("@Status", 0);
            if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
            {
                _sPara.Add("@UserId", Convert.ToInt64(Session[General.UserId].ToString()));
            }
            _dsUserList = _db.GetDataSet("sprocCXCRMGetBrokerDetails", _sPara);
            if (_dsUserList != null && _dsUserList.Tables.Count > 0)
            {
                _dtUser = _dsUserList.Tables[0];
            }
            if (_dtUser != null && _dtUser.Rows.Count > 0)
            {
                for (int i = 0; i < _dtUser.Rows.Count; i++)
                {
                    ddlUser.Items.Add(new ListItem(_dtUser.Rows[i]["BrokerCode"].ToString(), _dtUser.Rows[i]["BrokerCodeId"].ToString()));
                }
                ddlUser.Items.Insert(0, new ListItem("Select", "-1"));
            }
            else
            {
                ddlUser.Items.Clear();
                ddlUser.Items.Insert(0, new ListItem("None", "-1"));
            }

        if (ddlUserRole.Text == "200")
        {
            ddlUser.Items.Clear();
            ddlUser.Items.Insert(0, new ListItem("Admin", "0"));
            ddlUser.Items.Insert(0, new ListItem("None", "-1"));
        }
        else if (ddlUserRole.Text == "201")
        {
            ddlUser.Items.Clear();
            ddlUser.Items.Insert(0, new ListItem("Admin", "0"));
            ddlUser.Items.Insert(0, new ListItem("None", "-1"));
        }
        else if (ddlUserRole.Text == "300")
        {
            ddlUser.Items.Clear();
            ddlUser.Items.Insert(0, new ListItem("Cashier", "0"));
            ddlUser.Items.Insert(0, new ListItem("None", "-1"));
        }
    }

    public void LoadBroker()
    {
        lblError.Text = "";
        DataTable _dtSummary = new DataTable();
        Int16 User = 0;//Convert.ToInt16(ddlUser.Text);
        Int16 Campaign = Convert.ToInt16(ddlCampaign.Text);
        Int32 Renewal = Convert.ToInt16(ddlRenewal.Text);
        Int16 Status = 1;
        Int64 BrokerId = Convert.ToInt64(txtAgentId.Text.Trim());

        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        string _spName = "sprocBrokerSelectItemList";
        SortedList _sPara = new SortedList();

        _sPara.Add("@User", User);
        _sPara.Add("@Campaign", Campaign);
        _sPara.Add("@Renewal", Renewal);
        _sPara.Add("@Status", Status);
        _sPara.Add("@BrokerId", BrokerId);

        _dtSummary = _db.GetDataTableBySP(_spName, _sPara);
        if (_dtSummary != null && _dtSummary.Rows.Count > 0)
        {
            txtContactId.Text = _dtSummary.Rows[0]["ContactId"].ToString();
            txtProfileId.Text = _dtSummary.Rows[0]["ProfileId"].ToString();
            txtActiveStatus.Text = _dtSummary.Rows[0]["ActiveStatus"].ToString();
            Int16 ActiveStatus = 1;
            if (_dtSummary.Rows[0]["ActiveStatus"].ToString().ToUpper() == "FALSE")
            {
                ActiveStatus = 0;
            }
            txtActiveStatus.Text = ActiveStatus.ToString();
            ddlUserRole.Text = _dtSummary.Rows[0]["Ninfo4"].ToString();
            if (_dtSummary.Rows[0]["BrokerCodeId"].ToString() == "101")
            {
                ddlUser.Items.Clear();
                ddlUser.Items.Add(new ListItem("Cashier", "0"));
            }
            else if (_dtSummary.Rows[0]["BrokerCodeId"].ToString() == "102")
            {
                ddlUser.Items.Clear();
                ddlUser.Items.Add(new ListItem("Admin", "0"));
            }
            else
            {
                ddlUser.Items.Clear();
                ddlUser.Items.Add(new ListItem(_dtSummary.Rows[0]["BrokerCode"].ToString(), _dtSummary.Rows[0]["BrokerCodeId"].ToString()));
            }
            txtEmail.Text = _dtSummary.Rows[0]["Email"].ToString();
            txtPassword.Text = _dtSummary.Rows[0]["Password"].ToString();
            ddlRenewal.Text = _dtSummary.Rows[0]["Ninfo6"].ToString();
            ddlCampaign.Text = _dtSummary.Rows[0]["Ninfo5"].ToString();
            ddlBrokerLevel.Text = _dtSummary.Rows[0]["Info1"].ToString();
            txtLicenseNumber.Text = _dtSummary.Rows[0]["License"].ToString();
            txtTHContact.Text = _dtSummary.Rows[0]["THPhone"].ToString();
            txtENContact.Text = _dtSummary.Rows[0]["ENPhone"].ToString();
            if (ddlUserRole.Text == "100")
            {
                int enlenth = _dtSummary.Rows[0]["ENPhone"].ToString().Length;
                int thlenth = _dtSummary.Rows[0]["THPhone"].ToString().Length;
                txtENContact.Text = _dtSummary.Rows[0]["ENPhone"].ToString().Substring(enlenth - 4, 4);
                txtTHContact.Text = _dtSummary.Rows[0]["THPhone"].ToString().Substring(thlenth - 4, 4);
            }
            txtDIDNumber.Text = _dtSummary.Rows[0]["DID"].ToString();
            txtTHFirstName.Text = _dtSummary.Rows[0]["THFirstName"].ToString();
            txtTHLastName.Text = _dtSummary.Rows[0]["THLastName"].ToString();
            txtENFirstName.Text = _dtSummary.Rows[0]["ENFirstName"].ToString();
            txtENLastName.Text = _dtSummary.Rows[0]["ENLastName"].ToString();
            txtNickName.Text = _dtSummary.Rows[0]["NickName"].ToString();
            DateTime _dob = CE.Global.General.GetUTCDateTime();
            if (!DateTime.TryParse(_dtSummary.Rows[0]["DOBDate"].ToString(), out _dob))
            {
                _dob = CE.Global.General.GetUTCDateTime();
            }
            ddlDay.Text = _dob.Day.ToString("00");
            ddlMonth.Text = _dob.Month.ToString("00");
            ddlYear.Text = _dob.Year.ToString("0000");
            ddlGender.Text = "M";
            if (_dtSummary.Rows[0]["Gender"].ToString() == "Female")
            {
                ddlGender.Text = "F";
            }
            if (_dtSummary.Rows[0]["Info10"].ToString() != string.Empty && _dtSummary.Rows[0]["Info10"].ToString().Length == 8)
            {
                string EffFrom = CE.Global.General.GetUTCDateTime().ToString("yyyyMMdd");
                EffFrom = _dtSummary.Rows[0]["Info10"].ToString();
                ddlEffYear.Text = EffFrom.Substring(0, 4);
                ddlEffMonth.Text = EffFrom.Substring(4, 2);
                ddlEffDay.Text = EffFrom.Substring(6, 2);
            }
            //if (_dtSummary.Rows[0]["EffectiveTo"].ToString() != string.Empty && _dtSummary.Rows[0]["Info10"].ToString().Length == 8)
            //{
            //    lblEffectiveUpTo.Text = _dtSummary.Rows[0]["EffectiveTo"].ToString();
            //}
        }
    }

    private void LoadBroker(Int16 BrokerCodeId, string BrokerCode)
    {
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        DataSet _dsUserList = new DataSet();
        DataTable _dtUser = new DataTable();
        SortedList _sPara = new SortedList();
        _sPara.Add("@BrokerCodeId", BrokerCodeId);
        _sPara.Add("@BrokerCode", BrokerCode);
        _dsUserList = _db.GetDataSet("sprocCXCRMGetBrokerDetailsByBrokerCodeId", _sPara);
        if (_dsUserList != null && _dsUserList.Tables.Count > 0)
        {
            _dtUser = _dsUserList.Tables[0];
        }

        if (_dtUser != null && _dtUser.Rows.Count > 0)
        {
            txtEmail.Text = _dtUser.Rows[0]["Email"].ToString();
            txtENContact.Text = _dtUser.Rows[0]["ENContactNo"].ToString();
            txtTHContact.Text = _dtUser.Rows[0]["THContactNo"].ToString();
            if (ddlUserRole.Text == "100")
            {
                int enlenth = _dtUser.Rows[0]["ENContactNo"].ToString().Length;
                int thlenth = _dtUser.Rows[0]["THContactNo"].ToString().Length;
                txtENContact.Text = _dtUser.Rows[0]["ENContactNo"].ToString().Substring(enlenth - 4, 4);
                txtTHContact.Text = _dtUser.Rows[0]["THContactNo"].ToString().Substring(thlenth - 4, 4);
            }
            txtDIDNumber.Text = _dtUser.Rows[0]["DID"].ToString();
            txtLicenseNumber.Text = _dtUser.Rows[0]["License"].ToString();
        }
        else
        {
            ClearProcess();
        }
    }

    private string GetAutoPassword()
    {
        string _RandomPassword = "GGbr";
        if (ddlUserRole.Text == "300")
        {
            _RandomPassword = "GGch";
        }
        if (ddlUserRole.Text == "200" || ddlUserRole.Text == "201")
        {
            _RandomPassword = "GGad";
        }
        int _randomlen = 4;
        Random random = new Random();
        for (int i = 0; i < _randomlen; i++)
        {
            _RandomPassword += random.Next(0, 9).ToString();
        }
        return _RandomPassword;
    }

    public string GetMonth(string month)
    {
        string result = "";
        if (month == "01")
        {
            result = " Jan";
        }
        else if (month == "02")
        {
            result = " Feb";
        }
        else if (month == "03")
        {
            result = " Mar";
        }
        else if (month == "04")
        {
            result = " Apr";
        }
        else if (month == "05")
        {
            result = " May";
        }
        else if (month == "06")
        {
            result = " Jun";
        }
        else if (month == "07")
        {
            result = " Jul";
        }
        else if (month == "08")
        {
            result = " Aug";
        }
        else if (month == "09")
        {
            result = " Sep";
        }
        else if (month == "10")
        {
            result = " Oct";
        }
        else if (month == "11")
        {
            result = " Nov";
        }
        else if (month == "12")
        {
            result = " Dec";
        }
        return result;
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    public bool CheckDOBValid()
    {
        bool _Valid = true;
        if (!ValidDate(Convert.ToInt32(ddlYear.Text), Convert.ToInt32(ddlMonth.Text), Convert.ToInt32(ddlDay.Text)))
        {
            _Valid = false;
        }
        return _Valid;
    }

    public bool CheckEffectiveDateValid()
    {
        bool _Valid = true;
        if (!ValidDate(Convert.ToInt32(ddlEffYear.Text), Convert.ToInt32(ddlEffMonth.Text), Convert.ToInt32(ddlEffDay.Text)))
        {
            _Valid = false;
        }
        return _Valid;
    }

    private void CheckPageAccess()
    {
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 0)
        {
            Response.Redirect("~/UserMessage.aspx?menu=0&mt=UM&ec=101");
        }
        else if (PageAccess > 0)
        {
            EnablePageAccess(PageAccess);
        }
    }

    private void EnablePageAccess(Int64 PageAccess)
    {
        if (PageAccess == 100)
        {
            btnSubmit.Enabled = false;
        }
        else if (PageAccess == 300)
        {
            btnSubmit.Enabled = true;
        }
    }

}
